package com.xyzq.webapp.action.ya.report;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.opensymphony.xwork2.Preparable;
import com.xyzq.model.ya.data.Account;
import com.xyzq.model.ya.data.Staff;
import com.xyzq.model.ya.report.NewOpenAccount;
import com.xyzq.service.ya.AccountManager;
import com.xyzq.service.ya.StaffManager;
import com.xyzq.webapp.action.BaseAction;

public class NewOpenAccountReportAction extends BaseAction implements
		Preparable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8831572723533248991L;

	private Date start;
	private Date end;
	private List<NewOpenAccount> newOpenAccountList;
	private List<Account> accountList;
	private List<Account> accountShList;
	private List<Account> accountSzList;
	private AccountManager accountManager;
	private StaffManager staffManager;

	public String execute() {
		this.accountList = this.accountManager.findAccountByDate(start, end);
		this.accountShList = this.accountManager
				.findShAccountByDate(start, end);
		this.accountSzList = this.accountManager
				.findSzAccountByDate(start, end);
		for (Account account : this.accountList) {
			for (NewOpenAccount noa : this.newOpenAccountList) {
				if (account.getStaff().equals(noa.getStaff())) {
					noa.setOpenAccount(noa.getOpenAccount() + 1);
				}
			}
		}

		for (Account account : this.accountShList) {
			for (NewOpenAccount noa : this.newOpenAccountList) {
				if (account.getStaff().equals(noa.getStaff())) {
					noa.setOpenShAccount(noa.getOpenShAccount() + 1);
				}
			}
		}

		for (Account account : this.accountSzList) {
			for (NewOpenAccount noa : this.newOpenAccountList) {
				if (account.getStaff().equals(noa.getStaff())) {
					noa.setOpenSzAccount(noa.getOpenSzAccount() + 1);
				}
			}
		}
		this.logUserAction("NewOpenAccountReprotAction", "query:"+this.start+"<->"+this.end);
		return SUCCESS;
	}

	public void prepare() throws Exception {
		// TODO Auto-generated method stub
		List<Staff> staffList = this.staffManager.getAll();
		this.newOpenAccountList = new ArrayList<NewOpenAccount>();
		for (Staff staff : staffList) {
			NewOpenAccount noa = new NewOpenAccount(staff);
			this.newOpenAccountList.add(noa);
		}
	}

	public Date getStart() {
		return start;
	}

	public Date getEnd() {
		return end;
	}

	public List<NewOpenAccount> getNewOpenAccountList() {
		return newOpenAccountList;
	}

	public List<Account> getAccountList() {
		return accountList;
	}

	public AccountManager getAccountManager() {
		return accountManager;
	}

	public void setStart(Date start) {
		this.start = start;
	}

	public void setEnd(Date end) {
		this.end = end;
	}

	public void setNewOpenAccountList(List<NewOpenAccount> newOpenAccountList) {
		this.newOpenAccountList = newOpenAccountList;
	}

	public void setAccountList(List<Account> accountList) {
		this.accountList = accountList;
	}

	public void setAccountManager(AccountManager accountManager) {
		this.accountManager = accountManager;
	}

	public void setStaffManager(StaffManager staffManager) {
		this.staffManager = staffManager;
	}

	public StaffManager getStaffManager() {
		return staffManager;
	}

	public void setAccountShList(List<Account> accountShList) {
		this.accountShList = accountShList;
	}

	public List<Account> getAccountShList() {
		return accountShList;
	}

	public void setAccountSzList(List<Account> accountSzList) {
		this.accountSzList = accountSzList;
	}

	public List<Account> getAccountSzList() {
		return accountSzList;
	}

}
